#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main(int argc, char* argv[])
{
  int fd;
  int i;
  int data = 0;
  int recv_data;
  unsigned char buf[102] = {0};
  int rvl;
  printf("%s\n",argv[0]);

   if(argc >=2)
  {
    data = atoi(argv[1]);
  }
  printf("data:%d\n",data);
  
  fd = open("/dev/flly_chrdev", O_RDWR);
  
  if(fd == -1)
  {
    perror("error open\n");
    exit(-1);
  }

  printf("open /dev/flly_chrdev success\n");

  //read data
  rvl = read(fd, &recv_data, sizeof(int));
  
  if(rvl < 0)
  {
    perror("read error\n");
  }
  printf("read success recv_data:%d rvl:%d\n",recv_data, rvl);

  //write data
  rvl = write(fd, &data, sizeof(data));
  if(rvl < 0)
  {
    perror("write error\n");
  }    
  
  printf("write success data:%d rvl:%d\n",data,  rvl);
  
  //read data
  rvl = read(fd, &recv_data, sizeof(int));
  
  if(rvl < 0)
  {
    perror("read error\n");
  }
  printf("read success recv_data:%d rvl:%d\n",recv_data, rvl);


  //close device
  close(fd);
  
  
  
  return 0;
}